package view;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.mortbay.util.ajax.Continuation;
import org.mortbay.util.ajax.ContinuationSupport;



/**
 * Servlet implementation class WaitForFileServlet
 */

public class WaitForMessageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	
   /**
    * @see HttpServlet#HttpServlet()
    */
   public WaitForMessageServlet() {
       super();
       
   } 

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("WaitForMessageServlet");
		String userID = request.getRequestURI().substring(request.getRequestURI().lastIndexOf("/")+1);
		Continuation  cc = ContinuationSupport.getContinuation(request, null);
		
		//if queue not suspend
		System.out.println("before suspend");
		SendMessagesToUserSocket.getInstance().addContinuation(userID, cc); //suspend
		System.out.println("after suspend");
		//resume..
		return;
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	      // Check that we have a file upload request

	}



}
